package com.newreports.cleaner;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import org.w3c.tidy.Tidy;
import org.w3c.tidy.TidyMessage;
import org.w3c.tidy.TidyMessageListener;

public class HtmlCleaner {

    public static void clean(final InputStream in, final OutputStream out) {
        Tidy tidy = new Tidy();
        tidy.setXHTML(true);
        tidy.setPrintBodyOnly(true);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PrintWriter p = new PrintWriter(os, true);
        tidy.setErrout(p);
        
        tidy.setQuiet(true);
        tidy.setShowErrors(0);
        tidy.setShowWarnings(false);
        tidy.setMessageListener(new TidyMessageListener() {
            @Override
            public void messageReceived(TidyMessage tm) {
                System.out.println(tm.getMessage());
            }
        });
        tidy.parse(in, out);

    }
}
